import {DrawInfoData} from "./o1DrawInterface";
import O1HD from "../../../engines/gameEngine";

const {ccclass, property} = cc._decorator;

@ccclass
export default class drawDetail extends cc.Component {

    @property(cc.Graphics)
    gdi: cc.Graphics = null;
    @property(cc.Label)
    lbTitleName: cc.Label = null;

    onLoad() {
    }

    private m_drawInfo: DrawInfoData = null;

    start() {

    }

    setInfo(drawInfo: DrawInfoData) {
        this.m_drawInfo = drawInfo;
        this.lbTitleName.string = this.m_drawInfo.name;
        //
        this.OnShowGdi();
    }

    OnShowGdi() {
        for (let data of this.m_drawInfo.drawList) {
            const {isStart, color, lineWidth, x, y} = data;
            const {r, g, b} = color;
            this.gdi.lineWidth = lineWidth;
            this.gdi.strokeColor = cc.color(r, g, b);
            if (isStart) {
                this.gdi.moveTo(x - 1, y - 1);
                this.gdi.lineTo(x, y);
                this.gdi.stroke();
            } else {
                this.gdi.lineTo(x, y);
                this.gdi.stroke();
                this.gdi.moveTo(x, y);
            }
        }
    }

    OnBtnDelete() {
        O1HD.emit('drawRecord.OnDeleteDraw', this.m_drawInfo.name);
    }

    OnBtnEdit() {
        O1HD.emit('drawRecord.OnEditDraw', this.m_drawInfo.name);
    }

    // update (dt) {}
}
